package com.ruoyi.back.controller;

import java.util.List;

import com.ruoyi.back.domain.Mechanism;
import com.ruoyi.back.service.IMechanismService;
import com.ruoyi.common.utils.uuid.SnowflakeIdUtils;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 院校、讲师、团队、机构Controller
 * 
 * @author luguanqing
 * @date 2021-04-06
 */
@Api(value="讲师团队信息",description = "讲师团队信息接口")
@RestController
@RequestMapping("/back/mechanism")
public class MechanismController extends BaseController
{
    @Autowired
    private IMechanismService mechanismService;

    /**
     * 查询院校、讲师、团队、机构列表
     */
    //@PreAuthorize("@ss.hasPermi('system:mechanism:list')")
    @ApiOperation(value="查询讲师团队列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    @GetMapping("/list")
    public TableDataInfo list(Mechanism mechanism)
    {
        startPage();
        List<Mechanism> list = mechanismService.selectMechanismList(mechanism);
        return getDataTable(list);
    }

    /**
     * 查询首页四家院校、讲师、团队、机构
     *
     * @return 院校、讲师、团队、机构集合
     */
    @ApiOperation(value="查询首页四家讲师团队")
    @GetMapping("/indexMechanism")
    public AjaxResult selectMechanismIndex(){
        List<Mechanism> list = mechanismService.selectMechanismIndex();
        return AjaxResult.success(list);
    }

    /**
     * 导出院校、讲师、团队、机构列表
     */
    //@PreAuthorize("@ss.hasPermi('system:mechanism:export')")
    @Log(title = "院校、讲师、团队、机构", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Mechanism mechanism)
    {
        List<Mechanism> list = mechanismService.selectMechanismList(mechanism);
        ExcelUtil<Mechanism> util = new ExcelUtil<Mechanism>(Mechanism.class);
        return util.exportExcel(list, "mechanism");
    }

    /**
     * 获取院校、讲师、团队、机构详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:mechanism:query')")
    @ApiOperation(value="获取讲师团队详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(name="id",value="讲师团队id",required=true)@PathVariable("id") String id)
    {
        return AjaxResult.success(mechanismService.selectMechanismById(id));
    }

    /**
     * 新增院校、讲师、团队、机构
     */
    //@PreAuthorize("@ss.hasPermi('system:mechanism:add')")
    @ApiOperation(value="新增讲师团队")
    @Log(title = "院校、讲师、团队、机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(name="讲师团队对象",value="传入json格式",required=true)@RequestBody Mechanism mechanism)
    {
        mechanism.setId(String.valueOf(new SnowflakeIdUtils(0, 0).nextId()));
        return toAjax(mechanismService.insertMechanism(mechanism));
    }

    /**
     * 修改院校、讲师、团队、机构
     */
    //@PreAuthorize("@ss.hasPermi('system:mechanism:edit')")
    @ApiOperation(value="修改讲师团队")
    @Log(title = "院校、讲师、团队、机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(name="讲师团队对象",value="传入json格式",required=true)@RequestBody Mechanism mechanism)
    {
        return toAjax(mechanismService.updateMechanism(mechanism));
    }

    /**
     * 删除院校、讲师、团队、机构
     */
    //@PreAuthorize("@ss.hasPermi('system:mechanism:remove')")
    @ApiOperation(value="删除讲师团队")
    @Log(title = "院校、讲师、团队、机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam(name="id",value="讲师团队id",required=true)@PathVariable String[] ids)
    {
        return toAjax(mechanismService.deleteMechanismByIds(ids));
    }
}
